from src.apps.master_window import GcanViewTemplate
import sys, os
import json

from src.apps.bolijiare.window import app_window as bolijiare_app_window
from src.apps.zuoyianmo.window import app_window as zuoyianmo_app_window
from src.apps.yuanchengqidong.window import app_window as yuanchengqidong_app_window

class GcanView(GcanViewTemplate):
    pass
    def __init__(self, app:str=None):
        ## 命令行传入参数，用于选择用户测试窗口界面
        # FIXME: 下面两句的顺序不能颠倒，否则会报错
        self.option_program = app
        super().__init__()

    def userWindowInit(self):
        # 根据输入的参数不同，初始化不同的用户窗口

        if self.option_program =='zuoyianmo':
        # 座椅检测弹出窗口
             zuoyianmo_app_window(self)
        elif self.option_program =='bolijiare':
        # 玻璃加热、喷嘴加热弹出窗口
             bolijiare_app_window(self)
        elif self.option_program =='yuanchengqidong':
        # 远程启动弹出窗口
             yuanchengqidong_app_window(self)

if 1:
    # 加载动态库,为打包使用
    if hasattr(sys, "frozen"):
        os.environ["PATH"] = sys._MEIPASS + ":" + os.environ["PATH"]
    """
    读取数据
    """

def get_option_program(cmdargs):
    '''
    优先获取命令行参数，从命令行参数设定useapp
    其次从配置文件appConfig.json中获取useapp
    默认选择zuoyianmo
    '''
    if len(cmdargs) > 1:
        return cmdargs[1]
    else:

        try:
            with open("./config/appConfig.json", 'r') as f:
                appConfig = json.load(fp=f)
                return appConfig['useapp']
        except:
            return 'zuoyianmo'
            # return 'bolijiare'


def main(cmdargs):

    app = get_option_program(cmdargs)
    root = GcanView(app = app)
    root.mainloop()


if __name__ == "__main__":
    cmdargs = sys.argv
    main(cmdargs)
    

